<template>
  <j-modal
    title="流程历史"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    :maskClosable="false"
    :destroyOnClose="true"
    :footer="null"
    @cancel="handleCancel"
    cancelText="关闭"
  >
    <div>
      <a-collapse v-model="activitiKey" accordion :destroyInactivePanel="true">
        <a-collapse-panel v-for="(item, index) in procInstList" :key="index" :header="'流程实例' + item">
          <process-detail :proc-inst-id="item" :bussiColumns="columns" :auditHisUrl="auditHisUrl"></process-detail>
        </a-collapse-panel>
      </a-collapse>
    </div>
  </j-modal>
</template>

<script>
  import {getAction} from '@/api/manage'
  import ProcessDetail from './components/ProcessDetail'

  export default {
    name: 'ProcessList',
    components: {
      ProcessDetail,
    },
    props: {
      formTableName: {
        type: String
      },
      columns: {
        type: Array,
        default: () => {
          return [];
        }
      },
      auditHisUrl: {
        type: String,
        default: '',
      },
      proInstUrl: {
        type: String,
        default: '',
      },
    },
    data() {
      return {
        activitiKey: ['0'],
        visible: false,
        confirmLoading: false,
        loading: true,
        width: '90%',
        procInstList: [],
        url: {
          list: '/process/queryProcessHisByDataId',
        },
      }
    },
    methods: {
      show(dataId) {
        this.requestData(dataId)
        this.visible = true
      },
      close() {
        this.$emit('close')
        this.visible = false
      },
      // 查询数据
      requestData(dataId) {
        this.loading = true
        if (this.proInstUrl) {
          let params = {dataId: dataId} //查询条件
          this.procInstList = []
          getAction(this.proInstUrl, params)
            .then((res) => {
              if (res.success) {
                this.procInstList = res.result
              } else {
                this.$message.warn('加载失败')
              }
            })
            .catch((e) => {
              console.error(e)
            })
            .then(() => {
              this.loading = false
            })
        } else {
          let params = {dataId: dataId, formTableName: this.formTableName} //查询条件
          this.procInstList = []
          getAction(this.url.list, params)
            .then((res) => {
              if (res.success) {
                this.procInstList = res.result
              } else {
                this.$message.warn('加载失败')
              }
            })
            .catch((e) => {
              console.error(e)
            })
            .then(() => {
              this.loading = false
            })
        }
      },
      handleCancel() {
        this.close()
      },
    },
  }
</script>

<style scoped>
</style>